package com.job.dao.Impl;

import com.job.dao.UserDao;
import com.job.model.User;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("userDao")
public class UserDaoImpl implements UserDao {
    SessionFactory sessionFactory;
    @Override
    public User getUser(String userName, String userPassWord) {
        Session session= sessionFactory.openSession();

       Query query= session.createQuery(" from User as u where u.userName='"+userName+"' and u.userId='"+userPassWord+"'");
       List list= query.getResultList();
      if (list.isEmpty()){
          return null;
      }else {
          return (User) list.remove(0);
      }

    }

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }
}
